package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Link;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;

/**
 * The element FRBRalias is the metadata property containing additional
 * well-known names of the document in the respective level of the FRBR
 * hierarchy
 * 
 * <pre>
 * <xsd:element name="FRBRauthor">
 *   <xsd:complexType>
 * 		<xsd:complexContent>
 * 			<xsd:extension base="metaopt">
 * 				<xsd:attributeGroup ref="link"/>
 * 				<xsd:attribute name="as" type="xsd:anyURI"/>
 * 			</xsd:extension>
 *   	</xsd:complexContent>
 *   </xsd:complexType>
 * </xsd:element>
 * </pre>
 * 
 * @see http://www.ietf.org/rfc/rfc2396.txt
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 * 
 */
public final class FRBRauthor extends MetaOpt implements Link{

	public static final String ELEMENT = "FRBRauthor";
	
	public static final String ATTRIBUTE_AS = "as";
	
	private String _href;
	private String _as;
	
	/**
	 * @see org.akomantoso.core.data.attribute.Link#getHref()
	 */
	public String getHref() {
		return _href;
	}
	
	/**
	 * @see org.akomantoso.core.data.attribute.Link#setHref(java.lang.String)
	 */
	public void setHref(String href) {
		_href = href;
	}
	
	public String getAs() {
		return _as;
	}
	
	public void setAs(String as) {
		_as = as;
	}
	
	/**
	 * @see org.akomantoso.core.data.MetaOpt#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeLink(out, this);
		if (_as != null) {
			out.writeAttribute(ATTRIBUTE_AS, _as);
		}
		super.writeExternal(out);
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.data.MetaOpt#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		super.readExternal(in);
		_href = in.readAttribute(Link.ATTRIBUTE);
		_as = in.readAttribute(ATTRIBUTE_AS);
	}
	
}